/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nc.kyiv.yellow.sociallibrary.dao;

import com.nc.kyiv.yellow.sociallibrary.ConnectionManager.ConnectionManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;

/**
 *
 * @author My
 */
public class ConstantsDAO {

    DataSource source = null;
    Map<String, Integer> result = null;

    public Map<String, Integer> initialiseConstants(String tableName) {
        Connection conn = null;

        String query = "SELECT * FROM " + tableName;

        try {
            conn = ConnectionManager.getConnection();
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(query);
            result = new HashMap<>();
            while (rs.next()) {
                result.put(rs.getString(2), rs.getInt(1));
            }

        } catch (SQLException ex) {
            System.out.println("Error: " + ex.getMessage());
        } finally {
            if (conn != null) {
                ConnectionManager.releaseConnection(conn);
            }
        }
        return result;
    }
}
